GBML manual / Collision

tile_class

The tile class at (x, y) in the current room’s collision tile layer - one of TILE_PASS, TILE_SOLID or TILE_LOW_COVER (compare with ==). tile_solid/tile_blocks_projectile already answer "does this block me" directly; reach for tile_class instead when a project needs to test for TILE_PASS explicitly.

Syntax

tile_class(x, y) -> tile_kind

Arguments

NameType
xreal
yreal

Returns

tile_kind

Description

The tile class at (x, y) in the current room's collision tile layer - one of TILE_PASS, TILE_SOLID or TILE_LOW_COVER. Compare it with ==.

x and y are a place in the room, counted from the room's top-left corner. That is also where the tile grid starts, so the very first tile covers x from 0 to 7 and y from 0 to 7 (tiles are 8 by 8 pixels).

tile_solid and tile_blocks_projectile already answer "does this block me" directly, and are the right call for ordinary movement/collision code. Reach for tile_class instead when a project needs to test for TILE_PASS explicitly, or tell TILE_SOLID and TILE_LOW_COVER apart for something other than the body/projectile questions those two functions already answer.

There are three classes, not four

An earlier version of this engine also had TILE_VOID - a fourth class, identical to TILE_LOW_COVER for collision (both blocked a body, both let a projectile pass), kept only so a project's own code and the editor could tell two visually-different tiles apart (TILE_LOW_COVER reading as duckable cover, TILE_VOID as a pit). It was removed: nothing in this engine's own class ever behaved differently for the two, no shipped project ever painted either one, and the distinction it existed for - purely what a project draws or means by a tile, never what it blocks - was never the engine's to know or enforce in the first place.

A project that wants a pit still paints TILE_LOW_COVER and gives it pit behavior itself, by reading tile_class(x, y)/tile_solid and writing the fall-damage, draw-order or death-trigger logic in its own GBML - the class only ever needed to expose the mechanic (blocks a body, a projectile passes over), never a visual label for it.

TILE_LOW_COVER can be changed at runtime with tile_set_class - which changes collision only, never what is drawn. See Tile animation for the engine's actual mechanism for changing what a tile looks like.

Example

if (tile_class(x, y + 8) == TILE_LOW_COVER) {
    var crouched = true;
}

Checks the tile just below the walker and, if it's duckable cover, marks the walker as crouched - tile_solid/tile_blocks_projectile alone can't tell TILE_LOW_COVER apart from TILE_SOLID for the body question (both block it), so a project that needs to react to TILE_LOW_COVER specifically reaches for tile_class instead.

On the GBA

A point outside the room reads as TILE_PASS. The edge of a room is not a wall: a moving thing that reaches it keeps going and leaves the room. To keep things in, paint Solid collision along the edge, or check the position in code (room_left, room_right, room_top and room_bottom give the four edges). A room with no tile layer at all has no map to be outside of, so every point there reads as TILE_PASS. A raw attribute byte whose class bits are 3 (no name here since TILE_VOID was removed) decodes the same way, for the same reason.

See also: tile_solidtile_blocks_projectiletile_flagstile_set_classTile animationTILE_PASS